﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>职称设置</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
    <script src="https://unpkg.com/element-plus/dist/index.full.min.js"></script>
    <style>
        .Aaa {
            margin: 10px;
            margin-left: 0px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>您正在做的业务是：人力资源--客户化设置--人力资源档案管理设置--职称设置</div>
        <el-button class="Aaa" type="primary" v-on:click="goToAddPage">添加</el-button>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="major_name" label="职称名称"></el-table-column>
            <el-table-column label="操作">
                <template #default="scope">
                    <el-button size="small" type="primary" v-on:click="() => goToUpdatePage(scope.row.major_zwid)">修改</el-button>
                    <el-button size="small" type="button" v-on:click="confirmDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <script>
        const { createApp, ref } = Vue;

        const app = createApp({
          setup() {
              const tableData = ref([]);

              // 获取职称数据
              function fill() {
                  axios.get('/ZCSZ/GetTitles')
                  .then(res => {
                      console.info(res.data);
                      tableData.value = res.data.list;
                  }).catch(err => {
                      console.info(err)
                  })
              }

              // 确认删除对话框
              const confirmDelete = (row) => {
                  ElementPlus.ElMessageBox.confirm(
                      `确定要删除职称 "${row.major_name}" 吗？`,
                      '删除确认',
                      {
                          confirmButtonText: '确认删除',
                          cancelButtonText: '取消',
                          type: 'warning',
                      }
                  )
                  .then(() => {
                      // 用户点击确认，执行删除操作
                      deleteTitle(row);
                  })
                  .catch(() => {
                      // 用户点击取消，不执行任何操作
                      ElementPlus.ElMessage.info('已取消删除');
                  });
              };

              function deleteTitle(row){
                  axios.delete(`/ZCSZ/Delete/${row.major_zwid}`)
                    .then(res => {
                        console.info(res.data);
                        if(res.data.zhi>0){
                          fill();
                          ElementPlus.ElMessage.success('删除成功');
                        }else{
                            ElementPlus.ElMessage.error('删除失败，请重试');
                        }
                    }).catch(err => {
                        console.info(err)
                    })
                 }

              function goToAddPage(){
                 window.location.href = '/ZCSZ/Add';
              }

              function goToUpdatePage(id){
                 window.location.href = `/ZCSZ/Upd?id=${id}`;
              }

              //加载数据
              fill();

              return {
                  tableData,
                  confirmDelete,
                  deleteTitle,
                  goToAddPage,
                  goToUpdatePage
              }
          }
        });

        app.use(ElementPlus);
        app.mount('#app');
    </script>
</body>
</html>